package com.lframework.xingyun.basedata;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import org.assertj.core.util.Lists;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;

public class CodeGenerator {

    private static final List<String> TABLE_LIST = Lists.newArrayList("tl_army_product_info");
    public static void main(String[] args) {
        Path path = Paths.get(System.getProperty("user.dir"));
        TemplateConfig templateConfig = new TemplateConfig.Builder()
                .controller("null")
                        .build();

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/xingyun",
                        "root",
                        "7212413WEnmu")
                .globalConfig(builder -> builder
                        .author("bogewang")
                        .outputDir(path + "/xingyun-basedata/src/main/java")
                        .commentDate("yyyy-MM-dd")
                        .disableOpenDir()
                )
                .packageConfig(builder -> builder
                        .parent("com.lframework.xingyun.basedata")
                        .entity("entity")
                        .mapper("mappers")
                        .service("service")
                        .serviceImpl("service.impl")
                        .pathInfo(Collections.singletonMap(OutputFile.xml, path + "/xingyun-basedata/src/main/resources/mappers")) // 设置mapperXml生成路径

                )
                .strategyConfig(builder -> builder
                        .addTablePrefix("tbl_", "tl_")// 设置过滤表前缀
                        .addInclude(TABLE_LIST)
                        .entityBuilder()
                        .enableLombok()
                        .enableTableFieldAnnotation() // 启用字段注解
                        .enableFileOverride()
                )
                .templateConfig(template ->
                    template.controller("")
                            .build()
                )
                .execute();
    }
}
